package day15;

/**
 * @author tongchen
 * @create 2023-03-22 19:16
 */
public class Test {
    public static void main(String[] args) {
        int[]nums={0,1,2,3,4,5,6,7,9};
        System.out.println(missingNumber(nums));
    }
    public static int missingNumber(int[] nums) {
        //思路：先二分再顺序遍历
        int newLeft=0;
        int newRight=0;
        int left=0;
        int right=nums.length-1;
        while(left<right){
            int mid=((right-left)>>1)+left;
            if(nums[mid]!=mid){
                newRight=nums[mid];
                right=mid;
            }else{
                newLeft=nums[mid];
                left=mid+1;
            }
        }
        return left;
    }
}
